"""
@author: Kenneth Tse  xie.kenneth@gmail.com
"""


class Filter:
    def __init__(self, inStream, outStream, filter, blockSize = 1024*256):
        self._in = inStream
        self._out = outStream
        self._filter = filter    
        self._blockSize = blockSize
        self._inSize = 0
        self._outSize = 0
        
    def process(self):
        while True:
            if self._in.tell() == self._in.getSize():
                break
            passed = self._filter.filter(self._in, self._blockSize)
            self._out.write(passed)
    
    
#if __name__ == "__main__":
#    from sumtool import SumFilter
#    from stream.binarystream import BinaryStream
#    #rar = BinaryStream("f:/PPA401.rar", True)
#    rar = BinaryStream("f:/test.txt", True)
#    rar.open()    
#    
#    md5sum = BinaryStream("f:/sum.txt")
#    md5sum.open()
#    
#    sumf = SumFilter("md5")
#    
#    f = Filter(rar, md5sum, sumf, 2)
#    
#    f.process()
    
#        while True:
#            data = self._in.read(self._blockSize)
#            if original:
#                self._inSize += len(data)
#                passed = self._filter.filter(data)
#                self._outSize += len(passed)
#            else:
#                break;


